﻿
using Xacml.Core;
using System;
using System.Xml;

namespace Xacml.Core.Context
{
  public class StatusCodeElement : XacmlElement
  {
    private StatusCodeElement _statusCode;
    private string _value;

    public StatusCodeElement InnerStatusCode
    {
      get
      {
        return this._statusCode;
      }
    }

    public string Value
    {
      get
      {
        return this._value;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return true;
      }
    }

    public StatusCodeElement(XmlReader reader, XacmlVersion schemaVersion)
      : base(XacmlSchema.Context, schemaVersion)
    {
      if (reader.LocalName == "StatusCode")
      {
        this._value = reader.GetAttribute("Value");
        if (reader.IsEmptyElement)
          return;
        while (reader.Read())
        {
          switch (reader.LocalName)
          {
            case "StatusCode":
              this._statusCode = new StatusCodeElement(reader, schemaVersion);
              break;
          }
          if (reader.LocalName == "StatusCode" && reader.NodeType == XmlNodeType.EndElement)
            break;
        }
      }
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    public StatusCodeElement(string value, StatusCodeElement statusCode, XacmlVersion schemaVersion)
      : base(XacmlSchema.Context, schemaVersion)
    {
      this._value = value;
      this._statusCode = statusCode;
    }
  }
}
